home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / clib37x.lha / CLib37x / source / lib_source / LibInit.c < prev    next >
C/C++ Source or Header  |  1999-03-02  |  6KB  |  167 lines

  1. /*
  2. **      $VER: LibInit.c 37.32 (2.3.99)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996-99 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/libraries.h>
  15. #include <exec/execbase.h>
  16. #include <exec/resident.h>
  17. #include <exec/initializers.h>
  18.  
  19. #ifdef __MAXON__
  20. #include <clib/exec_protos.h>
  21. #else
  22. #include <proto/exec.h>
  23. #endif
  24. #include "compiler.h"
  25.  
  26. #ifdef __GNUC__
  27. #include "../include/example/examplebase.h"
  28. #elif VBCC
  29. #include "include/example/examplebase.h"
  30. #else
  31. #include "/include/example/examplebase.h"
  32. #endif
  33.  
  34. ULONG __saveds __stdargs L_OpenLibs(struct ExampleBase *ExampleBase);
  35. void  __saveds __stdargs L_CloseLibs(void);
  36.  
  37. struct ExecBase      *SysBase       = NULL;
  38. struct IntuitionBase *IntuitionBase = NULL;
  39. struct GfxBase       *GfxBase       = NULL;
  40.  
  41. #define VERSION  37
  42. #define REVISION 32
  43.  
  44. #define EXLIBNAME "example"
  45. #define EXLIBVER  " 37.32 (2.3.99)"
  46.  
  47. char __aligned ExLibName [] = EXLIBNAME ".library";
  48. char __aligned ExLibID   [] = EXLIBNAME EXLIBVER;
  49. char __aligned Copyright [] = "(C)opyright 1996-99 by Andreas R. Kleinert. All rights reserved.";
  50.  
  51. char __aligned VERSTRING [] = "\0$VER: " EXLIBNAME EXLIBVER;
  52.  
  53. /* ----------------------------------------------------------------------------------------
  54.    ! ROMTag and Library inilitalization structure:
  55.    !
  56.    ! Below you find the ROMTag, which is the most important "magic" part of a library
  57.    ! (as for any other resident module). You should not need to modify any of the
  58.    ! structures directly, since all the data is referenced from constants from somewhere else.
  59.    !
  60.    ! You may place the ROMTag directly after the LibStart (-> StartUp.c) function as well.
  61.    !
  62.    ! Note, that the data initialization structure may be somewhat redundant - it's
  63.    ! for demonstration purposes.
  64.    !
  65.    ! EndResident can be placed somewhere else - but it must follow the ROMTag and
  66.    ! it must not be placed in a different SECTION.
  67.    ---------------------------------------------------------------------------------------- */
  68.  
  69. extern ULONG InitTab[];
  70. extern APTR EndResident; /* below */
  71.  
  72. struct Resident __aligned ROMTag =     /* do not change */
  73. {
  74.  RTC_MATCHWORD,
  75.  &ROMTag,
  76.  &EndResident,
  77.  RTF_AUTOINIT,
  78.  VERSION,
  79.  NT_LIBRARY,
  80.  0,
  81.  &ExLibName[0],
  82.  &ExLibID[0],
  83.  &InitTab[0]
  84. };
  85.  
  86. APTR EndResident;
  87.  
  88. struct MyDataInit                      /* do not change */
  89. {
  90.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  91.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  92.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  93.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  94.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  95.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  96.  ULONG ENDMARK;
  97. } DataTab =
  98. #ifdef VBCC
  99. {
  100.         0xe000,8,NT_LIBRARY,
  101.         0x0080,10,(ULONG) &ExLibName[0],
  102.         0xe000,LIBF_SUMUSED|LIBF_CHANGED,
  103.         0xd000,20,VERSION,
  104.         0xd000,22,REVISION,
  105.         0x80,24,(ULONG) &ExLibID[0],
  106.         (ULONG) 0
  107. };
  108. #else
  109. {
  110.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  111.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  112.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  113.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  114.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  115.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  116.  (ULONG) 0
  117. };
  118. #endif
  119.  
  120.  
  121. /* ----------------------------------------------------------------------------------------
  122.    ! L_OpenLibs:
  123.    !
  124.    ! Since this one is called by InitLib, libraries not shareable between Processes or
  125.    ! libraries messing with RamLib (deadlock and crash) may not be opened here.
  126.    !
  127.    ! You may bypass this by calling this function fromout LibOpen, but then you will
  128.    ! have to a) protect it by a semaphore and b) make sure, that libraries are only
  129.    ! opened once (when using global library bases).
  130.    ---------------------------------------------------------------------------------------- */
  131.  
  132. ULONG __saveds __stdargs L_OpenLibs(struct ExampleBase *ExampleBase)
  133. {
  134.  SysBase = (*((struct ExecBase **) 4));
  135.  
  136.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  137.  if(!IntuitionBase) return(FALSE);
  138.  
  139.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  140.  if(!GfxBase) return(FALSE);
  141.  
  142.  
  143.  ExampleBase->exb_IntuitionBase = IntuitionBase;
  144.  
  145.  ExampleBase->exb_GfxBase       = GfxBase;
  146.  ExampleBase->exb_SysBase       = SysBase;
  147.  
  148.  return(TRUE);
  149. }
  150.  
  151. /* ----------------------------------------------------------------------------------------
  152.    ! L_CloseLibs:
  153.    !
  154.    ! This one by default is called by ExpungeLib, which only can take place once
  155.    ! and thus per definition is single-threaded.
  156.    !
  157.    ! When calling this fromout LibClose instead, you will have to protect it by a
  158.    ! semaphore, since you don't know whether a given CloseLibrary(foobase) may cause a Wait().
  159.    ! Additionally, there should be protection, that a library won't be closed twice.
  160.    ---------------------------------------------------------------------------------------- */
  161.  
  162. void __saveds __stdargs L_CloseLibs(void)
  163. {
  164.  if(GfxBase)       CloseLibrary((struct Library *) GfxBase);
  165.  if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  166. }
  167.